﻿using SecsEquip;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace EquipSecs300
{
    public partial class EventBtnTrig : CMyFormEx
    {
        int ParamInt1 = 1;
        int ParamInt2 = 1;
        int ParamInt3 = 1;
        int ParamInt4 = 1;
        int ParamInt5 = 1;
        string ParamStr1 = "ParamStr1";
        string ParamStr2 = "ParamStr2";
        string ParamStr3 = "ParamStr3";
        string ParamStr4 = "ParamStr4";
        string ParamStr5 = "ParamStr5";
        SePresentData sePresentData;
        public GEM_Even Even { get; set; }

        public EventBtnTrig(SecsEquipHelper secsEquipHelper)
        {
            m_pViewName = "EventDetail";
            this.secsEquipHelper = secsEquipHelper;
            InitializeComponent();

        }
        public override void UpdateData()
        {
            GetComomParam();
        }
        private void GetComomParam()
        {
            ParamInt1 = UtilitiesConvert.StringToInt32(textBoxParamInt1.Text);
            ParamInt2 = UtilitiesConvert.StringToInt32(textBoxParamInt2.Text);
            ParamInt3 = UtilitiesConvert.StringToInt32(textBoxParamInt3.Text);
            ParamInt4 = UtilitiesConvert.StringToInt32(textBoxParamInt4.Text);
            ParamInt5 = UtilitiesConvert.StringToInt32(textBoxParamInt5.Text);
            ParamStr1 = textBoxParamStr1.Text;
            ParamStr2 = textBoxParamStr2.Text;
            ParamStr3 = textBoxParamStr3.Text;
            ParamStr4 = textBoxParamStr4.Text;
            sePresentData = new SePresentData() { WAFERID = "WAFERID007", WAFER_ST = 1, PORTNO = 1, SLOTNO = 1, WFRESULT = 0 , WAFERID_Lot = "WAFERID_Lot007" };
            sePresentData.SeInspCommonItem = new SeInspCommonItem() { INTIME = "202312121212", OUTTIME = "202311111111", PPID = "PPID007", CHECK_POINT_X_POS = 13579, CHECK_POINT_Y_POS = 02468, PortFoupID = "PortFoupID007" };
        }
        private void btnSetParam_Click(object sender, EventArgs e)
        {
            GetComomParam();
        }
        private void btnTrigConditionRes_Click(object sender, EventArgs e)
        {
            Even.Ev_EQStatesChange_R();
            Even.Ev_EQDoorStates_R();
            Even.Ev_EapState_R();
            Even.Ev_PortFoupStates_R();
            Even.Ev_PortFoupArrived_R();
            Even.Ev_PortFoupUnloadButLockd_R();
            Even.Ev_PortSlopMap_R();
            Even.Ev_FoupWaferFetchOut_R();
            Even.Ev_WaferBackFoup_R();
            //Even.Ev_ARM2_Take_FOUP_Wafer_R();
            //Even.Ev_ARM2_Wafer_Back_FOUP_R();
            Even.Ev_AlignerGetWafer_R();
            Even.Ev_AlignerOutWafer_R();
            Even.Ev_InspectGetWafer_R();
            Even.Ev_InspectOutWafer_R();
            Even.Ev_InspectFolwStart_R();
            Even.Ev_InspectFolwEnd_R();
            Even.Ev_AlignerReadWaferID_R();
            Even.Ev_MEASURE_Result_Report_Item_R();
            Even.Ev_RecipeChangeSucc_R();

            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_LoadPortLoadReady_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_LoadPortUnloadReady_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_LoadPortLoaded_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_BoxCarrierClamped_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_ReadCarrierSucc_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_ReadCarrierFail_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_BoxCarrierOpened_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_BoxCarrierClosed_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_BoxCarrierUnClamped_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_LoadPortUnLoaded_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_ReadCarrierSlotSucc_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_RecipeChangeSucc_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_BoxCarrierProcessStart_R();
            secsEquipHelper.LoadPort.MapPort["Port_1"].Ev_BoxCarrierProcessEnd_R();

            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_LoadPortLoadReady_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_LoadPortUnloadReady_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_LoadPortLoaded_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_BoxCarrierClamped_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_ReadCarrierSucc_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_ReadCarrierFail_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_BoxCarrierOpened_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_BoxCarrierClosed_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_BoxCarrierUnClamped_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_LoadPortUnLoaded_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_ReadCarrierSlotSucc_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_RecipeChangeSucc_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_BoxCarrierProcessStart_R();
            secsEquipHelper.LoadPort.MapPort["Port_2"].Ev_BoxCarrierProcessEnd_R();


        }
        private void button1_Click(object sender, EventArgs e)
        {
            Even.Ev_EQStatesChange((DeviceMode_KE)ParamInt1, (DeviceStatus_KE)ParamInt2);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            Even.Ev_EQDoorStates((EfemEqSafetyDoorStatus_KE)ParamInt1, (InspEqSafetyDoorStatus_KE)ParamInt1);
        }

        private void button3_Click(object sender, EventArgs e)
        {
            Even.Ev_EapState((EAPConnectionStatus_KE)ParamInt1);
        }

        private void button4_Click(object sender, EventArgs e)
        {

            Even.Ev_PortFoupStates((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1);
        }

        private void button5_Click(object sender, EventArgs e)
        {
            Even.Ev_PortFoupArrived((PortNO_KE)ParamInt1, (PortWaferStatus_KE)ParamInt1);
        }

        private void button6_Click(object sender, EventArgs e)
        {
            Even.Ev_PortFoupUnloadButLockd((PortNO_KE)ParamInt1, (PortWaferStatus_KE)ParamInt1);
        }

        private void button7_Click(object sender, EventArgs e)
        {
            //Even.Ev_PortFoupStart((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button8_Click(object sender, EventArgs e)
        {
            //Even.Ev_PortFoupEnd((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button9_Click(object sender, EventArgs e)
        {
            List<ushort> mapList = new List<ushort>();
            for (int i = 0; i < 25; i++)
            {
                if (true||i == 2 || i == 3 || i == 24)
                {
                    mapList.Add(1);
                }
                else
                {
                    mapList.Add(0);
                }
            }
            Even.Ev_PortSlopMap((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1, mapList);
        }

        private void button10_Click(object sender, EventArgs e)
        {
            Even.Ev_FoupWaferFetchOut(sePresentData);
        }

        private void button11_Click(object sender, EventArgs e)
        {
            //Even.Ev_ARM2_Take_FOUP_Wafer(sePresentData);
        }

        private void button12_Click(object sender, EventArgs e)
        {
            Even.Ev_WaferBackFoup(sePresentData);
        }

        private void button13_Click(object sender, EventArgs e)
        {
            //Even.Ev_ARM2_Wafer_Back_FOUP(sePresentData);
        }

        private void button14_Click(object sender, EventArgs e)
        {
            Even.Ev_AlignerGetWafer(sePresentData);
        }

        private void button15_Click(object sender, EventArgs e)
        {
            Even.Ev_AlignerOutWafer(sePresentData);
        }

        private void button29_Click(object sender, EventArgs e)
        {
            Even.Ev_InspectGetWafer(sePresentData);
        }
        private void button30_Click(object sender, EventArgs e)
        {
            Even.Ev_InspectOutWafer(sePresentData);
        }
        private void button16_Click(object sender, EventArgs e)
        {
            Even.Ev_InspectFolwStart(sePresentData);
        }

        private void button17_Click(object sender, EventArgs e)
        {
            Even.Ev_InspectFolwEnd(sePresentData);
        }

        private void button18_Click(object sender, EventArgs e)
        {
            Even.Ev_AlignerReadWaferID(ParamStr1, ParamStr2, sePresentData);
        }

        private void button20_Click(object sender, EventArgs e)
        {
            //Even.Ev_FOUP_Arrived((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button21_Click(object sender, EventArgs e)
        {
            //Even.Ev_FOUP_LOCKED((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button22_Click(object sender, EventArgs e)
        {
            //Even.Ev_FOUPID_READ((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button23_Click(object sender, EventArgs e)
        {
            //Even.Ev_FOUP_DOOR_OPENED((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button24_Click(object sender, EventArgs e)
        {
            //Even.Ev_FOUP_DOOR_CLOSE((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button25_Click(object sender, EventArgs e)
        {
            //Even.Ev_FOUP_UNLOCKED((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button26_Click(object sender, EventArgs e)
        {
            //Even.Ev_FOUP_REMOVED((PortNO_KE)ParamInt1, (PortFoupStatus_KE)ParamInt1, ParamStr1);
        }

        private void button27_Click(object sender, EventArgs e)
        {
            Dictionary<string, List<double>> checkRes = new Dictionary<string, List<double>>();
            for (int i = 0; i < 32; i++)
            {
                for (int j = 0; j < 4; j++)
                {
                    List<double> res = new List<double>();

                    for (int n = 0; n < 4; n++)
                    {
                        res.Add(0.001);
                    }
                    checkRes.Add($"Check_item_Name_" + i + "_" + j, res);
                }
                
            }
            Even.Ev_MEASURE_Result_Report_Item(sePresentData, ParamStr1, ParamStr2, ParamStr3, checkRes);
        }

        private void EventDetail_Load(object sender, EventArgs e)
        {

        }

        private void button11_Click_1(object sender, EventArgs e)
        {
            Even.Ev_RecipeChangeSucc(ParamStr1, ParamStr2, new List<int>());
        }
    }
}
